<template>
  <div class="home">
    
    <!-- <div class="message block">
      <div class="row">
        <h2 class="title">消息</h2>
        <div class="more">
          <el-button type="text" @click="$router.push('/msg_work')">查看更多></el-button>
        </div>
      </div>
      <ul class="list">
        <li v-for="(msg, index) in msgs" :key="index" @click="goTaskDetail(msg)">
          <div class="msg_title">
            <span class="read" :class="{unread: msg.msgStatus == 2}"></span>
            {{msg.msg}}
          </div>
          <div>{{msg.createTime}}</div>
        </li>
      </ul>
      <div v-if="!msgs.length">暂无数据</div>
    </div>
    <div class="work block">
      <div class="row">
        <h2 class="title">待办</h2>
        <div class="more">
          <el-button type="text" @click="$router.push('/msg_work?activeName=work')">查看更多></el-button>
        </div>
      </div>
      <ul class="list">
        <li v-for="(work, index) in works" :key="index" @click="goProjectDetail(work)">
          <div>{{work.notifyContent}}</div>
          <div>{{work.createTime}}</div>
        </li>
      </ul>
      <div v-if="!works.length">暂无数据</div>
    </div> -->
    <router-view></router-view>
  </div>
</template>
<script>
import httpSer from "@/http";
export default {
  name: "home",
  data() {
    return {
      msgs: [],
      works: [],
      totalMsg: 0
    };
  },
  created() {},
  mounted() {
    // this.getWorks();
    // this.getMsgs();
  },
  methods: {
    getWorks() {
      let url = "/userApproveTask/pageUserApproveTask";
      // userApproveTask/pageUserApproveTask
      let data = {
        userTaskStatus: 1
      };
      httpSer.post(url, data).then(res => {
        
        let works = res.records;
        if (works.length > 5) {
          works.splice(0, 5);
        }
        
        this.works = works;
      });
    },
    getTitle(bizType) {
      switch (bizType) {
        case 1:
          return "立项审批";
          break;
        case 2:
          return "结项申请";
          break;
        case 3:
          return "变更申请";
          break;
        default:
          return "未定义";
          break;
      }
    },
    goProjectDetail(work) {
      let path = "";
      let query = {
        id: work.bizId,
        bizType: work.bizType,
        status: "approve",
        taskType: work.userTaskStatus
      };
      if (work.bizType == 1 || work.bizType == 2) {
        path = "project/projectDetail";
      } else if (work.bizType == 3) {
        path = "project/alterationDetail";
      } else if (work.bizType == 4) {
        path = "/task/taskApprove";
      } else if (work.bizType == 5) {
        path = "/task/taskDetail";
      } else {
        alert("未定义bizType");
      }
      this.$router.push({
        path,
        query: query
      });
    },
    getMsgs() {
      let url = "/msgInfo/pageMsgInfo";
      let data = {
        msgStatus: 2
      };
      httpSer.post(url, data).then(res => {
        let msgs = res.records;
        if (msgs.length > 5) {
          msgs.splice(0, 5);
        }
        this.msgs = msgs;
        this.$store.dispatch('getTotalMsg')
      });
    },
    goTaskDetail(item) {
      console.log(item)
      let url = "/msgInfo/readMsg";
      let data = {
        id: item.id
      };
      httpSer.post(url, data).then(res => {
        this.$router.push({
          path: "/task/taskDetail",
          query: {
            id: item.bizId
          }
        });
      });
    }
  },
  filters: {},
  components: {}
};
</script>

<style lang="less" scope>
@import "./index.less";
</style>